package com.hema.auction.widget.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hema.auction.R;
import com.hema.auction.activity.MainActivity;
import com.hema.auction.event.GoShoppingEvent;
import com.hema.auction.utils.manager.ScreenManager;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 描述:空状态
 * 作者:john
 */
public class EmptyView extends LinearLayout {
    @BindView(R.id.iv_empty_img)
    ImageView ivEmptyImg;
    @BindView(R.id.tv_empty_tip)
    TextView tvEmptyTip;
    @BindView(R.id.tv_empty_btn)
    TextView tvEmptyBtn;
    public static final int I_AUCTION = 0;//我在拍
    public static final int MESSAGE = I_AUCTION + 1;//系统消息
    public static final int NOTICE = MESSAGE + 1;//公告消息
    public static final int ORDER = NOTICE + 1;//订单
    public static final int FOCUS = ORDER + 1;//收藏
    public static final int SUN = FOCUS + 1;//晒单
    public static final int GOOD_DETAIL_SUN = SUN + 1;//商品详情晒单
    public static final int OTHER = GOOD_DETAIL_SUN + 1;//其他

    public EmptyView(Context context) {
        super(context);
        init();
    }

    public EmptyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public EmptyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        ButterKnife.bind(this, LayoutInflater.from(getContext()).inflate(R.layout.layout_empty_view, this));
        tvEmptyBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ScreenManager.getInstance().popAllActivitys(MainActivity.class);
                EventBus.getDefault().post(new GoShoppingEvent());
            }
        });
        setViewType(OTHER);
    }


    public void setViewType(int type) {
        switch (type) {
            case I_AUCTION:
                ivEmptyImg.setImageResource(R.drawable.ic_no_auction);
                tvEmptyTip.setText(R.string.tips_empty_i_auction);
                tvEmptyBtn.setText(R.string.go_shopping);
                tvEmptyBtn.setVisibility(VISIBLE);
                break;
            case MESSAGE:
                ivEmptyImg.setImageResource(R.drawable.ic_no_msg);
                tvEmptyTip.setText(R.string.tips_empty_no_msg);
                tvEmptyBtn.setVisibility(GONE);
                break;
            case NOTICE:
                ivEmptyImg.setImageResource(R.drawable.ic_no_msg);
                tvEmptyTip.setText(R.string.tips_empty_no_notice);
                tvEmptyBtn.setVisibility(GONE);
                break;
            case ORDER:
                ivEmptyImg.setImageResource(R.drawable.ic_no_order);
                tvEmptyTip.setText(R.string.tips_empty_no_order);
                tvEmptyBtn.setText(R.string.go_shopping);
                tvEmptyBtn.setVisibility(VISIBLE);
                break;
            case FOCUS:
                ivEmptyImg.setImageResource(R.drawable.ic_no_focus);
                tvEmptyTip.setText(R.string.tips_empty_no_focus);
                tvEmptyBtn.setText(R.string.go_shopping);
                tvEmptyBtn.setVisibility(VISIBLE);
                break;
            case SUN:
                ivEmptyImg.setImageResource(R.drawable.ic_no_sun);
                tvEmptyTip.setText(R.string.tips_empty_no_sun);
                tvEmptyBtn.setText(R.string.go_shopping);
                tvEmptyBtn.setVisibility(VISIBLE);
                break;
            case GOOD_DETAIL_SUN:
                ivEmptyImg.setImageResource(R.drawable.ic_no_sun);
                tvEmptyTip.setText(R.string.tips_empty_no_sun);
                tvEmptyBtn.setVisibility(GONE);
                break;
            case OTHER:
                ivEmptyImg.setImageResource(R.drawable.ic_no_order);
                tvEmptyTip.setText(R.string.tips_empty_no_data);
                tvEmptyBtn.setVisibility(GONE);
                break;
        }
    }

}
